'use strict';

/**
 * @ngdoc function
 * @name webApp.controller:HomecontentCtrl
 * @description
 * # HomecontentCtrl
 * Controller of the webApp
 */

angular.module('webApp')
  .controller('homeContent', function ($scope,$location,promiseHome,cookie,searchParam,popBox,$timeout,$ionicLoading) {
    $scope.$on('$stateChangeSuccess',function(){
      if(typeof $scope.homeContentData == 'undefined' && $location.$$path == '/root/home'){
        $ionicLoading.show({
          template: '加载中...'
        });
      }
    });
    //惰性获取首页新闻
    promiseHome.homeData().then(function(data){
      $scope.homeContentData = data;
      $ionicLoading.hide();
    },function(){
      $ionicLoading.hide();
    });

    //第三方自动登录
    if(!cookie.getCookie('access_token') && searchParam.getUrl('token')){
      promiseHome.thirdAutoSignIn().then(function(data){
        promiseHome.signIn(data);
      });
    }
});
